﻿#region Copyright(C) 2012 NCS Pte. Ltd. All rights reserved.

// ==================================================================================================
// Copyright(C) 2012 NCS Pte. Ltd. All rights reserved.
//
// SYSTEM NAME	:   iConnect.Azure Application Framework
// COMPONENT ID :   NCS.IConnect.Azure.Diagnostics.AzureStorage.AzureStorageCloudBlobClient
// COMPONENT DESC:  	
//
// CREATED DATE/BY:  08 June 2012 / Lu Ya Ming
//
// REVISION HISTORY:	
// DATE/BY			SR#/CS/PM#/OTHERS		DESCRIPTION OF CHANGE
// ==================================================================================================

#endregion

using Microsoft.WindowsAzure.StorageClient;

namespace NCS.IConnect.Cloud.Core.AzureStorage
{
    /// <summary>
    /// The Azure storage cloud blob container.
    /// </summary>
    public class AzureStorageCloudBlobContainer : ICloudBlobContainer
    {
        private readonly CloudBlobContainer container;
        private readonly ICloudBlobClient serviceClient;

        /// <summary>
        /// Initializes a new instance of the <see cref="AzureStorageCloudBlobContainer"/> class.
        /// </summary>
        /// <param name="container">The container.</param>
        public AzureStorageCloudBlobContainer(CloudBlobContainer container)
        {
            this.container = container;
            this.serviceClient = new AzureStorageCloudBlobClient(this.container.ServiceClient);
        }

        /// <summary>
        /// Gets the service client.
        /// </summary>
        /// <value>
        /// The service client.
        /// </value>
        public ICloudBlobClient ServiceClient
        {
            get { return this.serviceClient; }
        }

        /// <summary>
        /// Creates if not exist.
        /// </summary>
        public void CreateIfNotExist()
        {
            this.container.CreateIfNotExist();
        }

        /// <summary>
        /// Gets the page BLOB reference.
        /// </summary>
        /// <param name="blobAddressUri">The BLOB address URI.</param>
        /// <returns></returns>
        public ICloudPageBlob GetPageBlobReference(string blobAddressUri)
        {
            return new AzureStorageCloudPageBlob(this.container.GetPageBlobReference(blobAddressUri));
        }

        /// <summary>
        /// Gets the BLOB reference.
        /// </summary>
        /// <param name="blobAddressUri">The BLOB address URI.</param>
        /// <returns></returns>
        public ICloudBlob GetBlobReference(string blobAddressUri)
        {
            return new AzureStorageCloudBlob(this.container.GetBlobReference(blobAddressUri));
        }
    }
}
